<script>
import { createPlayer } from '@/common/player';
export default {
	onLaunch: function () {
		const systemInfo = uni.getSystemInfoSync();
		/**
		 * 设置主题，用户配置优先
		 */
		if (['light', 'dark'].includes(uni.getStorageSync('theme'))) {
			this.$store.dispatch('theme/setTheme', uni.getStorageSync('theme'));
		} else if (['light', 'dark'].includes(systemInfo.theme)) {
			this.$store.dispatch('theme/setTheme', systemInfo.theme);
		} else {
			this.$store.dispatch('theme/setTheme', 'light');
		}
		this.initPlayer();
		this.initUserAuth();
	},
	onShow: function () {
		console.log('App Show');
	},
	onHide: function () {
		console.log('App Hide');
	},
	methods: {
		/**
		 * 初始化播放器
		 */
		initPlayer() {
			// 初始化播放器
			createPlayer();

			// 监听播放器事件
			//播放器工具类中，媒体播放器监听对应事件并发射，此处接受，转发给仓库
			uni.$on('popupOpen', () => this.$store.dispatch('setPageMetaOverflow', true));
			uni.$on('popupClose', () => this.$store.dispatch('setPageMetaOverflow', false));

			uni.$on('onPlay', () => {
				this.$store.dispatch('player/listenLyricIndex');
				return this.$store.dispatch('player/setPlayerStatus', { paused: false });
			});

			uni.$on('onPause', () => {
				this.$store.dispatch('player/cancelLyricIndex');
				return this.$store.dispatch('player/setPlayerStatus', { paused: true });
			});

			uni.$on('onCanplay', () => this.$store.dispatch('player/setLoading', false));

			uni.$on('onEnded', () => this.$store.dispatch('player/setPlayerNext'));

			uni.$on('onPrev', () => this.$store.dispatch('player/setPlayerPrev'));

			uni.$on('onNext', () => this.$store.dispatch('player/setPlayerNext'));

			uni.$on('onTimeUpdate', (player) => {
				this.$store.dispatch('player/setLoading', false);
				this.$store.dispatch('player/setPlayerStatus', {
					currentTime: player.currentTime,
					duration: player.duration
				});
			});
		},
		/**
		 * 若保存了cookie，获取用户信息
		 */
		initUserAuth() {
			// if (userStore.getIsAuth) userStore.getUserAccount();
		}
	}
};
</script>

<style lang="scss">
/* 导入字体图标 */
@import '@/static/iconfont/iconfont.css';

/*每个页面公共css */
* {
	// margin: 0;
	// padding: 0;
	// box-sizing: border-box;
}
page,
html,
body {
	/* 系统级变量 */
	/* 自定义导航栏高度 */
	--nav-tab-height-custom: 84.6rpx;

	/* tabbar高度 */
	// --tabbar-height-custom: 50px;
	--tabbar-height-custom: 0;

	/* 播放器高度 */
	--player-height-custom: 54px;
	font-family: open sans, Helvetica, Arial, sans-serif;
	-webkit-overflow-scrolling: touch;
	box-sizing: border-box;
}

.uni-app--showtabbar uni-page-wrapper::after {
	display: none;
}

//隐藏滚动条
::-webkit-scrollbar {
	display: none;
	width: 0 !important;
	height: 0 !important;
	-webkit-appearance: none;
	background: transparent;
}

// 文字省略 单行
.text-ellipsis-single {
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

// 文字省略 多行
.text-ellipsis-multi {
	white-space: pre-line;
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	overflow: hidden;
}

// .fixed-top {
.fixed-top {
	padding-top: calc(var(--my-status-bar-height) + var(--nav-tab-height-custom));
	box-sizing: border-box;
}

/* #ifdef H5 */
.fixed-bottom {
	// 底部占位
	padding-bottom: calc(var(--window-bottom) + var(--player-height-custom));
	box-sizing: border-box;
}
/* #endif */

/* #ifndef H5 */
.fixed-bottom {
	padding-bottom: calc(var(--window-bottom) + var(--player-height-custom) + constant(safe-area-inset-bottom));
	padding-bottom: calc(var(--window-bottom) + var(--player-height-custom) + env(safe-area-inset-bottom));
	box-sizing: border-box;
}
/* #endif */

.fixed-placeholder {
	width: 100%;
	background-color: transparent;
	height: calc(constant(safe-area-inset-bottom));
	height: calc(env(safe-area-inset-bottom));
}

// 隐形占位，用于observerAPI
.observer-placeholder {
	width: 100%;
	height: 100px;
	position: absolute;
	top: 0;
	left: 0;
	visibility: hidden;
}

// .fixbg {
// 	width: 100%;
// 	height: 100vh;

// 	position: fixed;

// 	left: 0;
// 	top: 0;
// 	background-image: url();
// 	background-size: cover;
// 	background-position: center;
// 	filter: blur(10px);
// 	transform: scale(1.2);
// }

// 通用属性
</style>
